package org.apache.osgimaker.analyse.algorithm.renderer;

import java.text.MessageFormat;

import org.apache.osgimaker.analyse.algorithm.graph.StrongComponent;


/**
 * Renderer of a {@link StrongComponent}. The renderer is based on a 
 * <tt>java.text.MessageFormat</tt> template. 
 * 
 */
public class TemplateBasedStrongComponentRenderer
                                      extends AbstractStrongComponentRenderer {
  private final MessageFormat _format;
  private final int _minimumNumber;

  /** 
   * Creates an instance for the specified template. 
   * @param template The template.
   * @param minimumSize Minimum number of vertices the {@link StrongComponent}
   *        should have to be rendered.
   */
  public TemplateBasedStrongComponentRenderer(String template,
                                              int minimumNumber) {
    _format = new MessageFormat(template);
    _minimumNumber = minimumNumber;
  }

  public String render(StrongComponent component) {
    String result = "";
    if (component.getNumberOfVertices() >= _minimumNumber) {
      String[] values = new String[3];
      values[0] = createName(component);
      values[1] = Integer.toString(component.getNumberOfVertices());
      values[2] = Integer.toString(component.getLongestWalk());
      result = _format.format(values);
    }
    return result;
  }
} //class